//
//  LearnSettingViewController.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "LearnSettingViewController.h"
#import "CustomizeProgressView.h"
@interface LearnSettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic ,strong)UITableView *tableView;

@property(nonatomic ,strong)NSArray *titleArray;

@property(nonatomic ,strong)UIView *tableFootorView;

@property(nonatomic ,strong)UIButton *finishedBtn;

@property(nonatomic ,strong)UIView *tableHeaderView;

@property(nonatomic ,strong)UISwitch *switchListen;

@property(nonatomic ,strong)UISwitch *switchRead;

@end

@implementation LearnSettingViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:lWhiteColor] backgroundColor:lClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(51, 51, 51, 1),NSFontAttributeName:MFontWithSize(18)} enableScrollEdgeAppearance:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"设置";
    // Do any additional setup after loading the view.
    [self setBackButtonIsHidden:NO];
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = lWhiteColor;
    self.finishedBtn.superview.y = self.tableView.height;
    self.switchRead =[self createSwitch];
    [self.switchRead addTarget:self action:@selector(changeToRead) forControlEvents:UIControlEventValueChanged];
    self.switchListen =[self createSwitch];
    [self.switchListen addTarget:self action:@selector(changeToListen) forControlEvents:UIControlEventValueChanged];
}
- (UISwitch *)createSwitch
{
    return [[UISwitch alloc] initWithFrame:CGRectMake(lScreenWidth - 10 - 44, 0, 44, 53)];
}
-(void)changeToRead{
    
}
-(void)changeToListen{
    
}
-(void)finishedBtnAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -UITableViewDelegate,UITableViewDelegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@""];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
    }
    
    [cell removeAllSubviews];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, lScreenWidth - 50 - 10, 52)];
    titleLab.text = self.titleArray[indexPath.row];
    titleLab.font = MFontWithSize(16);
    titleLab.textColor = rgba(51, 51, 51, 1);
    [cell addSubview:separateLineWithColor(CGRectMake(10, 51, lScreenWidth - 10, 1), rgba(229, 229, 229, 1))];
    [cell addSubview:titleLab];
    if ([self.titleArray[indexPath.section] isEqualToString:@"播放提醒模版音频"]) {
        
        [cell addSubview: self.switchListen];
       
        
    }
    if ([self.titleArray[indexPath.section] isEqualToString:@"单个词/句完成跟读后评价"]) {
        [cell addSubview: self.switchRead];
     
    }
   
   
    
    
   
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.titleArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 52;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 35;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, lScreenWidth,35)];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 19, lScreenWidth - 20, 16)];
    titleLabel.font = MFontWithSize(16);
    titleLabel.text = section == 0? @"听说模考": @"字体设置大小";
    [titleLabel setTextAlignment:NSTextAlignmentLeft];
    titleLabel.textColor = rgba(142, 142, 142, 1);
    [header addSubview:titleLabel];
    return header;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}
#pragma mark -getters and setters
-(UITableView *)tableView{
    if (!_tableView){
        _tableView =[[UITableView alloc] initWithFrame:CGRectMake(0, 0, lScreenWidth, lScreenHeight - lBottomDangerousAreaHeight - 55) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        _tableView.bounces = NO;
        [_tableView setBackgroundColor:lWhiteColor];
        [_tableView setSeparatorColor:lWhiteColor];
        [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 0)];
        [_tableView setTableFooterView:self.tableFootorView];
        [_tableView setTableHeaderView:self.tableHeaderView];
    }
    
    return _tableView;
}
- (NSArray *)titleArray
{
    if (!_titleArray) {
        _titleArray = @[@"播放提醒模版音频",@"单个词/句完成跟读后评价"];
    }
    return _titleArray;
}
-(UIButton *)finishedBtn
{
    if (!_finishedBtn)
    {
        _finishedBtn = [UIButton new];
        _finishedBtn.frame =CGRectMake(0, 0, lScreenWidth - 20, 45);
       
        _finishedBtn.selected =NO;
        [_finishedBtn setTitle:@"完成" forState:UIControlStateNormal];
        [_finishedBtn setTitleColor:lWhiteColor forState:UIControlStateNormal];
        [_finishedBtn.titleLabel setFont:MFontWithSize(18)];
        [_finishedBtn addTarget:self action:@selector(finishedBtnAction) forControlEvents:UIControlEventTouchUpInside];
        _finishedBtn.backgroundColor = lClearColor;
        UIView *btnView =[[UIView alloc] initWithFrame:CGRectMake(10, 65, lScreenWidth - 20, 45)];
        [btnView setAllCornersWithCornerRadius:22.5];
        // gradient
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0,0,lScreenWidth - 20,45);
        gl.startPoint = CGPointMake(1, 0.5);
        gl.endPoint = CGPointMake(0, 0.5);
        gl.colors = @[(__bridge id)[UIColor colorWithRed:41/255.0 green:241/255.0 blue:156/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:2/255.0 green:161/255.0 blue:249/255.0 alpha:1.0].CGColor];
        gl.locations = @[@(0), @(1.0f)];
        [btnView.layer addSublayer:gl];
        [btnView addSubview:self.finishedBtn];
        [self.view addSubview:btnView];
    }
    
    return _finishedBtn;
}
-(UIView *)tableHeaderView
{
    if (!_tableHeaderView)
    {
        
        _tableHeaderView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, lScreenWidth,72)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, lScreenWidth - 20, 22)];
        titleLabel.font = MFontWithSize(16);
        titleLabel.text = @"字体设置大小";
        [titleLabel setTextAlignment:NSTextAlignmentLeft];
        titleLabel.textColor = rgba(142, 142, 142, 1);
        [_tableHeaderView addSubview:titleLabel];
        CustomizeProgressView *fontView = [[CustomizeProgressView alloc] initWithFrame:CGRectMake(20, titleLabel.bottom + 20, lScreenWidth - 40, 34) titleArray:@[@"偏小",@"标准",@"",@"超大"] Progress:0.75];
        fontView.block = ^(double progress) {
            NSLog(@"HHHHHHHHHHH%f",progress);
        };
        [_tableHeaderView addSubview:fontView];
        
        UILabel *titleLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(10, fontView.bottom + 30, lScreenWidth - 20, 22)];
        titleLabel2.font = MFontWithSize(16);
        titleLabel2.text = @"声音播放速度";
        [titleLabel2 setTextAlignment:NSTextAlignmentLeft];
        titleLabel2.textColor = rgba(142, 142, 142, 1);
        [_tableHeaderView addSubview:titleLabel2];
        CustomizeProgressView *voiceView = [[CustomizeProgressView alloc] initWithFrame:CGRectMake(20, titleLabel2.bottom + 20, lScreenWidth - 40, 34) titleArray:@[@"慢速",@"正常",@"快速"] Progress:0.75];
        fontView.block = ^(double progress) {
            NSLog(@"HHHHHHHHHHH%f",progress);
        };
        [_tableHeaderView addSubview:voiceView];
        _tableHeaderView.height = voiceView.bottom + 30;
        [_tableHeaderView addSubview:separateLineWithColor(CGRectMake(0, _tableHeaderView.height - 1, lScreenWidth, 1), rgba(229, 229, 229, 1))];
        
    }
    
    return _tableHeaderView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
